package spaces;

import math.Summable;
import vectors.Direction;
import vectors.Vector;

public class ChargeableDirectionNode extends DirectionNode implements Chargeable{

	protected Vector charge;
	
	public ChargeableDirectionNode(String name) {
		super(name);
	}

	public ChargeableDirectionNode(String name, Direction dir) {
		super(name, dir);
		charge = Vector.zero(dir.getDOF()+1);
	}
	
	@Override
	public void setDir(Direction dir){
		super.setDir(dir);
		if(charge == null){
			charge = Vector.zero(dir.getDOF()+1);
		}
	}
	
	@Override
	public void addCharge(Summable ch){
		charge = charge.plus((Vector)ch);
	}
	
	@Override
	public void applyCharge(){
		//Apply charge
		location = getLocation().generateUnitVector().plus(charge).generateDirection();
		
		//Reset Charge to empty charge
		charge = Vector.zero(getLocation().getDOF()+1);
	}
}
